﻿using Microsoft.AspNetCore.Mvc;
using NlpTrainApp.Bll.RexUninlu;
using NlpTrainApp.Bll.Uie;
using System.Threading.Tasks;

namespace NlpTrainApp.Webapi
{
    /// <summary>
    /// Class TrainAppController.
    /// Implements the <see cref="Microsoft.AspNetCore.Mvc.ControllerBase" />
    /// </summary>
    /// <seealso cref="Microsoft.AspNetCore.Mvc.ControllerBase" />
    [ApiController]
    [Route("api/nlptrain")]
    public class ClassifyTrainController : ControllerBase
    {
        private readonly TrainServiceBll serviceBll;
        private readonly TrainRexUninluBll trainRexUninluBll;
        /// <summary>
        /// Initializes a new instance of the <see cref="ClassifyTrainController"/> class.
        /// </summary>
        /// <param name="serviceBll">The service BLL.</param>
        /// <param name="trainRexUninluBll"></param>
        public ClassifyTrainController(TrainServiceBll serviceBll, TrainRexUninluBll trainRexUninluBll)
        {
            this.serviceBll = serviceBll; this.trainRexUninluBll = trainRexUninluBll;
        }
        /// <summary>
        /// Classifies the train.生成uie的学习数据
        /// </summary>
        /// <returns></returns>
        [HttpGet("ClassifyTrain")]
        public async Task<string> ClassifyTrain(string code)
        {
            if (serviceBll.IsTrainIng)
            {
                return "0";
            }
            else
            {
                _ = serviceBll.StartTrain(false,code);
            }
            await Task.CompletedTask;
            return "1";
        }
        /// <summary>
        /// 生成RexUninlu训练数据
        /// </summary>
        /// <returns></returns>
        [HttpGet("CreateRexUninluTrainData")]
        public async Task<string> CreateRexUninluTrainData()
        {
            await trainRexUninluBll.CreateTrainFile();
            return "1";
        }
    }
}
